﻿from django.contrib.auth.models import User, AnonymousUser
from yazasport import settings
from userprofile.models import UserProfile, Friendship
from communication.models import PrivateMessage

def user_context(request):
    if request.user != AnonymousUser():
        try:
            return {
                'current_user': request.user, 
                'current_userprofile': request.profile, 
                'friendships_count': Friendship.get_count(request.profile.id)[0],
                'unread_messages_count': PrivateMessage.get_count(request.profile.id)[0],
                }
        except AttributeError:
            return {}
    else:
        return {}